package com.rajaev.dtu.tractor.interfaces;


import com.rajaev.dtu.tractor.domain.service.UserInfoDomain;
import com.rajaev.dtu.tractor.infrastructure.base.common.Constants;
import com.rajaev.dtu.tractor.infrastructure.base.errors.BusinessException;
import com.rajaev.dtu.tractor.interfaces.dto.LoginResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class AuthController {


    @Autowired
    UserInfoDomain userService;

    @PostMapping("/auth/login")
    public LoginResponseDto login(String loginName, String password) throws BusinessException {

        LoginResponseDto loginResponseDto = userService.auth(loginName, password);
        return loginResponseDto;
    }

    @PostMapping("/auth/logout")
    public void logout(HttpServletRequest request)  {
        String token = request.getHeader(Constants.Authorization);
        userService.logout(token);

    }
}
